<template>
    <div class="development">
        <search-form :searchArray="searchArray" :searchObj="searchForm" @search="getList">
        </search-form>
        <elTable :formData="formData" @getList="getList">
                <el-table-column prop="company" label="公司名称" align="center">
                    <template slot-scope="scope">
                        {{scope.row.company && scope.row.company.name || ''}}
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="账号" align="center"></el-table-column>
                <el-table-column prop="secretKey" label="秘钥" align="center"></el-table-column>
                <el-table-column prop="status" label="状态" align="center">
                    <template slot-scope="scope">
                        {{statusName[scope.row.status || 0]}}
                    </template>
                </el-table-column>
                <!-- <el-table-column prop="createTime" label="创建时间" align="center"></el-table-column> -->
                <el-table-column prop="action" label="操作" align="center" width="120px;" fixed="right">
                    <template slot-scope="scope">
                        <el-button type="text"  @click="examine(scope.row)">
                            {{scope.row.status == 0 ? '锁定' : '解锁'}}
                        </el-button>
                    </template>
                </el-table-column>
        </elTable>
    </div>
</template>
<script>
import elTable from "@/components/xForm/elTable"
import { mapGetters } from 'vuex'
export default {
    name: 'development',
    components: {
        elTable
    },
    data () {
        return {
            formData: {
                currentPage: 1,
                pageSize: 10,
                data: [],
                total: 0
            },
            searchForm: {
                name: '',
                stauts: '',
                companyId: ''
            },
            statusName: {
                '-1': '锁定',
                '0': '正常'
            },
            searchArray: [
                {
                    type: 'input',
                    value: '',
                    label: '账号名称',
                    placeholder: '请输入账号名称',
                    key: 'name'
                },
                {
                    type: 'select',
                    value: '',
                    label: '状态',
                    placeholder: '请选择',
                    key: 'stauts',
                    list: [
                    ]
                }
            ]
        }
    },
    computed: {
        ...mapGetters({
            enumAll: 'common/getEnumAll'
        }),
    },
    created () {
        this.getList()
        this.init()
    },
    methods: {
        init () {
            this.$set(this.searchArray[1], 'list', this.enumAll.UserStatus || [])
        },
        examine (item) {
            this.$confirm(`您确定要${item.status == -1 ? '解锁' : '锁定'}?`, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
                }).then(() => {
                    let param = {}
                    param = {
                        id: item.id,
                        status: item.status == -1 ? 0 : -1
                    }
                    this.$loading(true)
                    this.$api.userManage.putDeveloperChangeStatus(param).then(r => {
                        this.getList()
                    }).finally(() => {
                        this.$loading(false)
                    })
                }).catch(() => {
            })
        },
        getList (status = true) {
            if (!status) this.formData.currentPage = 1
            const {formData: {currentPage, pageSize}, searchForm} = this
            let param = {}
            param = {
                currentPage,
                pageSize
            }
            for ( let k in searchForm) {
                if (searchForm[k] !== '') {
                    param[k] = searchForm[k]
                }
            }
            this.$loading(true)
            this.$api.userManage.getDeveloperList(param).then(r => {
                this.formData.data = r.data && r.data.list || []
                this.formData.total = r.data.total || 0
            }).finally(() => {
                this.$loading(false)
            })
        }
    }
}
</script>
<style lang="scss" scoped>
.development {
    .search-form {
        margin-bottom: 16px;
    }
}
</style>